#!/bin/bash
function resizeroot(){
FREESIZE=$(vgdisplay |grep Free|awk '{print $7}'|awk -F "." '{print $1}')
ROOTSIZE=$(df -h|head -3|tail -1|awk -F "G" '{print $1}')
(( ROOTSIZE = $ROOTSIZE + $FREESIZE ))
ROOTPATCH=$(mount|grep _root|awk '{print $1}')
lvextend -L $ROOTSIZE"G" $ROOTPATCH
resize2fs -p $ROOTPATCH
}

function delhome(){
HOMELVNAME=$(lvdisplay |grep home|grep Path|awk -F "/" '{print $4}')
echo HOMELVNAME : $HOMELVNAME
if [ ! -n $HOMELVNAME ];then
resizeroot
else
VGNAME=$(lvdisplay |grep home|grep Path|awk -F "/" '{print $3}')
echo VGNAME : $VGNAME
HOMEPATH=$(mount|grep _home|awk '{print $3}')
echo HOMEPATH : $HOMEPATH
umount $HOMEPATH
sed -i '/$HOMELVNAME/d' /etc/fstab
lvremove -f $VGNAME/$HOMELVNAME
resizeroot
fi
}

delhome

#mount -o remount,rw /